<template>
    <transition name="modal">
        <div class="modal-mask" v-show="open">
            <div class="modal-wrapper">
                <div class="modal-container">
    
                    <div class="modal-header">
                        <div class="row">
                            <div class="col-lg-12">
                                <h4>添加checklist项</h4>
                            </div>
                            
                        </div>
                       
                        
                        <button type="button" class="close" @click="$emit('close')">
                            <i class="fa fa-times" aria-hidden="true"></i>
                        </button>
                    </div>
    
                    <div class="modal-body">
                        <div class="row">
                            <div class="col-lg-12">
                                <div class="form-horizontal">
                                    
                                    <div class="form-group">
                                        <label class="col-sm-4 control-label">Checklist项内容：</label>
                                        <div class="col-sm-8">
                                            <textarea class="form-control" v-model="name" cols="30" rows="10"></textarea>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-sm-4 control-label">指定序号：</label>
                                        <div class="col-sm-8">
                                            <input type="text" class="form-control" v-model="sort" placeholder="选填，请输入checklist所在序号">
                                            <span class="help-block m-b-none">*  若序号已存在，原有序号项及后续项将下移。</span>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-sm-4 control-label">CaseID：</label>
                                        <div class="col-sm-8">
                                            <select v-model="case_id" class="form-control">
                                                <option value="">请选择</option>
                                                <template v-for="(item,i) in $root.CASE_LIST">
                                                    <option :value="item.case_id" :key="i">{{item.case_id}}</option>
                                                </template>
                                            </select>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-sm-4 control-label">是否广告类：</label>
                                        <div class="col-sm-8">
                                            <p class="form-control-static">{{is_adv | advStr}}</p>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
    
                    <div class="modal-footer">
                        <button type="button" class="btn btn-primary" @click="editChecklist"> 保 存 </button>
                        <button type="button" class="btn btn-default" @click="$emit('close')"> 取 消 </button>
                    </div>
                </div>
            </div>
        </div>
    </transition>
</template>
<script>
import {tip,ajax} from '../../tools/tools.js'

export default {
    name: 'EditPromotionModal',
    data() {
        return {
            id:'',
            name:'',
            sort:'',
            case_id:'',
            is_adv:'0'
        }
    },
    props:{
        open:{
            type:Boolean,
            default:false
        },
        checklistId:{
            type:String,
            default:''
        }
    },
    computed:{
        
    },
    filters:{
        advStr(v){
            var sObj = {
                '0':'否',
                '1':'是'
            }

            return sObj[v];
        }
    },
    watch:{
        open(v,ov){
            
        },
        checklistId(v,ov){
            var self = this;
            if(v!=''){
                self.id = v;
                self.getChecklistDetail();   
            }
        }
    },
    methods: {
        getChecklistDetail(){
            var self = this;
            ajax.getChecklistDetail({
                param:{
                    id:self.id
                },
                cb(data){
                    self.name = data.data.name;
                    self.sort = data.data.sort;
                    self.case_id = data.data.case_id;
                    self.is_adv = data.data.is_adv;
                }
            })
        },
        editChecklist(){
            var self = this;
            if($.trim(self.name).length==0){
                tip.warn('请填写checklist项目内容');
                return false;
            }
            if($.trim(self.case_id).length==0){
                tip.warn('请填写检测项ID');
                return false;
            }
            ajax.editChecklist({
                param:{
                    id:self.checklistId,
                    name:self.name,
                    case_id:self.case_id,
                    sort:self.sort
                },
                cb(data){
                    self.$emit('editcldone');
                }
            })
        }
    },
    mounted() {
        
    }
}
</script>
<style scoped>
.close {
    position: absolute;
    right: 30px;
    top: 30px;
}

.modal-mask {
    position: fixed;
    z-index: 10001;
    top: 0;
    left: 0;
    bottom: 0;
    right: 0;
    background-color: rgba(0, 0, 0, .5);
    transition: opacity .3s ease;
}

.modal-wrapper {
    position: absolute;
    width: 100%;
    height: 1px;
    left: 0;
    right:0;
    top: 120px;
}

.limte-height{
    max-height: 250px;
    overflow-x: hidden;
    overflow-y: auto;
}

.modal-container {
    width: 800px;
    margin: 0px auto;
    padding: 20px 30px;
    background-color: #fff;
    border-radius: 2px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, .33);
    transition: all .3s ease;
    font-family: Helvetica, Arial, sans-serif;
    position: relative;
}

.modal-header h3 {
    margin-top: 0;
    color: #42b983;
}

.modal-default-button {
    float: right;
}

.modal-enter {
    opacity: 0;
}

.modal-leave-active {
    opacity: 0;
}

.modal-enter .modal-container,
.modal-leave-active .modal-container {
    -webkit-transform: scale(1.1);
    transform: scale(1.1);
}
</style>
